package com.jnu.bookstore;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class EditbookActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_editbook);
        Intent intent = getIntent();
        final int position = intent.getIntExtra("position", 0);
        final EditText editTextName = findViewById(R.id.edit_book_name);
        String name = intent.getStringExtra("name");
        if (null != name) {
            editTextName.setText(name);
        }

        Button buttonOK = this.findViewById(R.id.OK);
        Button buttonFalse = this.findViewById(R.id.No);

        buttonOK.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("position", position);
                intent.putExtra("name", editTextName.getText().toString());
                setResult(BookListFragment.RESULT_CODE_ADD_DATA, intent);
                EditbookActivity.this.finish();
            }
        });

        buttonFalse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditbookActivity.this.finish();
            }
        });
    }
}
